package Test.ThreadTest;

import km.org.apache.poi.hssf.usermodel.HSSFSheet;
import km.org.apache.poi.hssf.usermodel.HSSFWorkbook;
import km.org.apache.poi.poifs.filesystem.POIFSFileSystem;
import km.org.apache.poi.ss.usermodel.Cell;
import km.org.apache.poi.ss.usermodel.Row;
import weaver.general.Util;

import java.io.File;
import java.io.FileInputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-04-29
 * @Description: ${description}
 * @ModifyLog:
 **/

public class Test {
    public static void main(String[] args) throws Exception {
          String tax = "1%";
        double newsl = " ".equals( tax ) ? 0 : Util.getIntValue( tax.replace( "%", "" ) ) * 0.01;
        System.out.println(newsl);
    }

    public static String format2Double(double d) {
        DecimalFormat df = new DecimalFormat( "#0.00" );
        return df.format( d );
    }

    //判断发票税额是否是数字
    public static String isNumberType(String str) {
        Boolean strResult = str.matches( "-?[0-9]+.?[0-9]*" );
        String newStr = strResult == true ? format2Double(Double.valueOf( str )) : "0";
        return newStr;
    }

    public static void excel() throws Exception {
        //用流的方式先读取到你想要的excel的文件
        FileInputStream fis = new FileInputStream( new File( System.getProperty( "user.dir" ) + "/src/Test/excel.xls" ) );
        System.out.println( fis );
        //解析excel
        POIFSFileSystem pSystem = new POIFSFileSystem( fis );
        //获取整个excel
        HSSFWorkbook hb = new HSSFWorkbook( pSystem );
        System.out.println( hb.getNumCellStyles() );
        //获取第一个表单sheet
        HSSFSheet sheet = hb.getSheetAt( 0 );
        //获取第一行
        int firstrow = sheet.getFirstRowNum();
        //获取最后一行
        int lastrow = sheet.getLastRowNum();
        //循环行数依次获取列数
        for (int i = firstrow; i < lastrow + 1; i++) {
            //获取哪一行i
            Row row = sheet.getRow( i );
            if (row != null) {
                //获取这一行的第一列
                int firstcell = row.getFirstCellNum();
                //获取这一行的最后一列
                int lastcell = row.getLastCellNum();
                //创建一个集合，用处将每一行的每一列数据都存入集合中
                List<String> list = new ArrayList<>();
                for (int j = firstcell; j < lastcell; j++) {
                    //获取第j列
                    Cell cell = row.getCell( j );

                    if (cell != null) {
                        // System.out.print(cell+"\t");
                        list.add( cell.toString() );
                    }

                }
                System.out.println( "行数" + i );
                /*RecordSet rs = new RecordSet();
                    List batchsql = new ArrayList();
                    StringBuilder builder = new StringBuilder("insert into employee (yghname,age,sex) values (?,?,?)");
                    batchsql.add(list.get(1));
                    batchsql.add(list.get(2));
                    batchsql.add(list.get(3));
                    rs.executeUpdate(builder.toString(),batchsql.toArray());*/

                System.out.println();
            }
        }
        fis.close();
    }

}

